<?
    class SettingsController extends Principio_Library_ControllerAction
    {
        public function init()
        {
            parent::init();
        }


        public function indexAction()
        {
            $this->view->title = "Settings";
        }


        public function editAction()
        {
            if (($this->is_post) && ($this->checkPostItemInt("id", "Settings ID")))
            {
                $this->view->settings_id = $this->post_data['id'];
                switch ($this->view->settings_id)
                {
                    case 1:
                        $this->view->title = "View and edit Custom Profile Settings";
                        if ($this->is_apply)
                        {
                            if (!empty($this->post_data['global_template']) && !empty($this->post_data['global_account_template']))
                            {
                                Principio_Library_Common::checkValidity(Principio_Model_SettingsMapper::updateGlobalTemplates(Principio_Model_SettingsMapper::TEMPLATE_GLOBAL, $this->post_data['global_template']),
                                                                        "Can't save global template");
                                Principio_Library_Common::checkValidity(Principio_Model_SettingsMapper::updateGlobalTemplates(Principio_Model_SettingsMapper::TEMPLATE_EXT, $this->post_data['global_account_template']),                                                                        "Can't save ext template");

                                if (!Principio_Library_Common::$is_error)
                                    Principio_Library_Common::$msg = "Templates were changed.";
                            }
                            else
                                Principio_Library_Common::reportValidationFails("Fill all fields");
                        };



                        $template_global = Principio_Model_SettingsMapper::getGlobalTemplates(Principio_Model_SettingsMapper::TEMPLATE_GLOBAL);
                        $template_account_global = Principio_Model_SettingsMapper::getGlobalTemplates(Principio_Model_SettingsMapper::TEMPLATE_EXT);

                        if (isset($this->post_data['global_template']))
                            $this->view->template_global = $this->post_data['global_template'];
                        else
                            $this->view->template_global = $template_global;

                        if (isset($this->post_data['global_account_template']))
                            $this->view->template_account_global = $this->post_data['global_account_template'];
                        else
                            $this->view->template_account_global = $template_account_global;
                    break;

                    case 2:
                        $this->view->title = "View and Edit Audio DNS Settigns";

                    break;

                    case 3:
                        $this->view->title = "View and Edit Audio Codecs Settigns";
                        $this->view->codecs = Principio_Model_SettingsMapper::getAudioCodecs();
                    break;

                    case 4: // Firmwares
                        $this->view->title = "Firmwares";
                        break;

                    default:
                        Principio_Library_Common::reportValidationFails("Wrong settings ID");
                };
            };
        }
    }
?>